﻿namespace Gunningine
{
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;

    /// <summary>
    /// Base resource class.  Should always be loaded from ResourceManager
    /// as it is responsible for filling in properties.
    /// </summary>
    public abstract class Resource : IDisposable
    {
        /// <summary>
        /// Type, eg 'Image', 'Sound', etc.
        /// </summary>
        public string Type { get; set; }

        /// <summary>
        /// Name, could be filename, or a description.
        /// </summary>
        public string Name { get; set; }

        /// <summary>
        /// Filename.
        /// </summary>
        public string Filename { get; set; }

        /// <summary>
        /// Load resource.
        /// </summary>
        /// <param name="logger">logger instance.</param>
        public virtual void Load(IResourceLoader loader)
        {
            loader.Load(this);
        }

        /// <summary>
        /// Unload resource.  Called by IDisposable.
        /// </summary>
        public virtual void Unload()
        {
        }

        #region IDisposable implementation

        bool _disposed = false;

        public void Dispose()
        {
            if (!this._disposed)
            {
                Unload();
            }

            this._disposed = true;
        }

        #endregion

    }
}
